package com.twu.biblioteca.controllers;


public final class ConsoleMainMenu extends Console {

    @Override
    public void run() {

        try {
            this.io.getOutput().append("\nMain Menu\n\n1- List Books\n2- Checkout Book\n3- Return Book\n4- List Movie\n5- Checkout Movie\n6- Return Movie\n7- Info's user\n8- Quit\n\nOption:");
            System.out.println(this.io.getOutput());

            byte option = Byte.parseByte(this.io.getInput().nextLine());

            switch (option){
                case 1:
                    new ConsoleListBook().run();
                    break;
                case 2:
                    Console.checkPassword(new ConsoleCheckoutBook());
                    break;
                case 3:
                    Console.checkPassword(new ConsoleReturnBook());
                    break;
                case 4:
                    new ConsoleListMovie().run();
                    break;
                case 5:
                    Console.checkPassword(new ConsoleCheckoutMovie());
                    break;
                case 6:
                    Console.checkPassword(new ConsoleReturnMovie());
                    break;
                case 7:
                    new ConsoleInfo().run();
                    break;
                case 8:
                    System.exit(0);
                    break;
                default:
                    System.out.println("\n\tSelect a valid option!\n");
                    this.io.getOutput().delete(0, this.io.getOutput().length());
                    new ConsoleMainMenu().run();
            }
        }
        catch (NumberFormatException e){
            System.out.println("\n\tSelect a valid option!\n");
            this.io.getOutput().delete(0, this.io.getOutput().length());
            new ConsoleMainMenu().run();
        }
    }
}
